<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page contentType="text/html;charset=UTF-8"%>
<%@taglib uri="/struts-tags" prefix="s"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>">

		<link href="themes/css/ui.common.css" rel="stylesheet" type="text/css" />
		<link href=" themes/css/ui.child.css" rel="stylesheet" type="text/css" />
		<link href=" themes/css/ui.tips.css" rel="stylesheet" type="text/css" />
		<script src=" Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
		<script src=" Scripts/jquery-ui-1.8.custom.min.js"
			type="text/javascript"></script>
		<script src=" Scripts/ui.admincp.js" type="text/javascript"
			charset="UTF-8"></script>
		<script src=" Scripts/ui.tips.js" type="text/javascript"></script>
		<script src=" Scripts/ui.default.js " type="text/javascript"
			charset="UTF-8"></script>
		<link id="skin_css" rel="stylesheet" type="text/css"
			href=" themes/css/ui.c.blue.css"></link>
		<STYLE type="text/css">
			.editorArea {
				display: none;
			}
		</STYLE>
		<script type="text/javascript" src="Scripts/ui.dialogFormHelper.js"></script>
		<script type="text/javascript"><!--
		//鼠标点击的时候,出现编辑框,回车可以提交请求
		$(function(){
			registeRowFuncButton();
			$(".textPanel").click(function(){
			     var __id = $(this).attr("oid");
			     $("#sender_"+__id).click();
			     $("#editor_"+__id).focus();
			  });
		   $(".textBox").keydown(function(e){ 
		      
          		if(e.keyCode==13){ 
           			$("#sender_"+$(this).attr("oid")).click();//处理事件 
       			} 
          });  
		
		});
	function showEditor(id)
	{
	  
	   // row 
	   
	   var row = $("#row"+id);
	    
	   
	   var allEditableCol = $(row).find(".editableCol");
	   
	   for(var i=0;i<allEditableCol.length;i++)
	   {
		   var item = allEditableCol[i];
		  
		   var content = $(item).find(".textPanel:first");
		   var editorArea =  $(item).find(".editorArea:first");
		   
		   
		   var editor = $(item).find(".textBox:first");
		   
		   editor.val(content.text());
		   
		   editorArea.show(); 
		   content.hide(); 
	   }
	   	
	   $("#switcher_"+id).attr("src"," themes/icons/ok.png").attr("title","提交");
	   
	}
	
	function hideEdit(id,withSubmit)
	{
		   var row = $("#row"+id);
		    
		   var allEditableCol = $(row).find(".editableCol");
		   
		   var oldData = [];
		   var newData = [];
		   
		   for(var i=0;i<allEditableCol.length;i++)
		   {
			   var item = allEditableCol[i];
			  
			   var content = $(item).find(".textPanel:first");
			   var editorArea =  $(item).find(".editorArea:first");
			    
			   var editor = $(item).find(".textBox:first");
 
			   var newText = editor.val();
			   var oldText = content.text();
			   
			   newData.push(newText);
			   oldData.push(oldText);
			   
			   content.text(newText); 
			   
			   content.show();
			   editorArea.hide();
		   }
		   
	   //...
	   //显示原内容。。 
       //withSubmit
       //submit to Db
       if(withSubmit==true){
         if(newData.length>0)
         {
            //...
            //post to server...
                $.post("goodCategory!modify.action", 
               		{"categoryId":id,"categoryNo":newData[0],"categoryName":newData[1]},
                		 function (data) {  
                        }); 
         } 
     
       } 
	   
       $("#switcher_"+id).attr("src"," themes/icons/edit.png").attr("title","进行编辑");
     
	}
	
	function switchSave(id,withSubmit)
	{  
	 var ___id= "#sender_"+id ;
	  var sender= $(___id); 
	   var stateCode = sender.attr("state"); 
	   if(stateCode==0 || stateCode==undefined)
	   { 
	     // 进行保存 。 
	     $(sender).attr("state",1);  
	     showEditor(id); 
	
	   }
	   if(stateCode==1)
	   {
	     $(sender).attr("state",0);
	     $("#submitting").show();
	     hideEdit(id,withSubmit);  
	   }
	}

     function cancelSave(id,withSubmit)
     {
         switchSave(id,false);
          
     }
     
    function toDeleteHandler(e)
	{
		var categoryId = e.entityId;
		location.href="goodCategory!delete.action?categoryId="+categoryId;
	}
     
    function checkAll(str)
	{
 		var items = document.getElementsByName(str); //获取所有复选框
		var totalNum = items.length; //获取复选框的个数
 		for (var i=0; i<totalNum; i++)
 		items[i].checked = window.event.srcElement.checked;//通过单击的按钮判断是选中还是未选
	}
	
	function deleteAll(str)
	{
		var isTo = checkDeleteAll("物品类型信息记录");

		if(isTo==false)
		return ;
 		var items = document.getElementsByName(str); //获取所有复选框
		var totalNum = items.length; //获取复选框的个数
		var delStr = "";
 		for (var i=0; i<totalNum; i++){
 			if(items[i].checked == true){
				delStr += items[i].value + ","; 
			}
		}
		delStr = delStr.substring(0, delStr.length -1);
		location.href="goodCategory!delete.action?categoryIds="+delStr;
	}
	
	function add(){
		var categoryNo= $("#categoryNo").val();
		var categoryName= $("#categoryName").val();
		if($.trim(categoryNo).length==0){
			alert("请输入物品类型编码.");
			$("#categoryNo").focus();
			return false;
		}
		if($.trim(categoryName).length==0){
			alert("请输入物品名称.");
			$("#categoryName").focus();
			return false;
		}
		$.post("goodCategory!add.action", {"categoryNo":categoryNo,"categoryName":categoryName},function (data) {
			location.href="goodCategory!toQuery.action";
		});
	}
	-->
	</script>
	</head>

	<body>
		<div class="PageChild_Title">
			<img src=" themes/images/default/icons/archives.png" class="PageChild_Tbtnpic" />
			<span class="PageChild_separate"></span>
			<span class="PageChild_TbtnText"><h2>物品类型管理</h2></span>
			<span class="PageChild_separate"></span>
			<div id="marker" class="red-tips">
			</div>
			<div class="clear">
			</div>
		</div>
		<div class="PageChild_Where">
			<table style="height: 60px" border="0" cellpadding="0"
				cellspacing="0"> 
				<tr>
					<td style="width:80px;" class="mtd" valign="bottom">物品类型编码:</td>
					<td style="width:80px;" valign="top">
						<input name="txt_categoryNo" type="text" maxlength="50" id="categoryNo" style="width: 150px;" />
					</td>
					<td style="width:80px;" class="mtd" valign="bottom">物品类型名称:</td>
					<td style="width:80px;" valign="top">
						<input name="txt_categoryName" type="text" maxlength="50" id="categoryName" style="width: 150px;" />
					</td>
				</tr>
				<tr>
					<td colspan="4">
						<input type="button" value="添 加" class="o-btn SubmitButton" onclick='add();' />
					</td>
				</tr>
				<tr>
					<td colspan="4">
						<br />
						<s:if test="count!=null">
						<span id="lbl_list_count">共搜索到 <b>${count}</b> 条符合条件的记录。</span>
						</s:if> 
					</td>
				</tr>
			</table>
		</div>
		<div class="PageChild_List">
			<table width="100%" border="0" cellspacing="0"
				style="text-align: left">
				<tbody class="PageChild_List_head">
					<tr>
						<td width="16">
						    <input id="Chk_All" type="checkbox" name="Chk_All" onclick="checkAll('ReptShow$ctl01$Chk_Num')" />
						</td>
						<td width="16"><img src=" themes/images/default/icons/pcde_314.png" width="16" height="16" /></td>
						<td>
							物品类型编码
						</td>
						<td>
							物品类型名称
						</td>
						<td class="td_width40">
							编辑
						</td>
						<td class="td_width40">
							删除
						</td>
						<td class="td_width40">
							状态
						</td>
					</tr>
				</tbody>
				<tbody class="PageChild_List_main" style="text-align: left">
					<s:if test="goodCategoryList != null && goodCategoryList.size != 0">
					<s:iterator value="goodCategoryList" var="item" status="no">
						<tr class='td_no_bord' id="row${item.categoryId }" oid="${item.categoryId }">
							<td class="td_width25">
								<span title="24"><input id="Chk_Num" type="checkbox"
										name="ReptShow$ctl01$Chk_Num" value="${item.categoryId}"/></span>
							</td>
							<td class="td_width25"><s:property value="#no.count"/></td>
							<td title="单击内容进行编辑.回车提交更新." class="editableCol">
								<span oid="${item.categoryId}" class="textPanel"> ${item.categoryNo} </span>
								<div  class="editorArea">
									<input class="textBox"
										type="text" size="50" maxlength="40" oid="${item.categoryId}" />
								</div>
							</td>
							<td title="单击内容进行编辑.回车提交更新." class="editableCol">
								<span oid="${item.categoryId}" class="textPanel" > ${item.categoryName} </span>
								<div class="editorArea">
									<input  class="textBox"
										type="text" size="50" maxlength="40" oid="${item.categoryId}" />
								</div>
							</td>
							<td>
								<a class="editButton" id="sender_${item.categoryId}"
									href="javascript:void(0);" state="0"
									onclick="switchSave(${item.categoryId},true);"> <img
										id="switcher_${item.categoryId}" src=" themes/icons/edit.png"
										title="进行编辑" /> </a> &nbsp;
							</td>
							<td>
								<a href="javascript:;" class="ui-link-delete-button"
									entityId="${item.categoryId}" onclick=''><img
										src="themes/icons/delete.png" /> </a>
							</td>
							<td>
							<s:if test="#item.states==0">
									<a href="javascript:;"
									onclick='location="goodCategory!toEnable.action?categoryId=${item.categoryId}"'><img
										src=" themes/icons/btn_disable.png" /> </a>
							</s:if>
							<s:if test="#item.states==1">
									<a href="javascript:;"
									onclick='location="goodCategory!toDisable.action?categoryId=${item.categoryId}"'><img
										src=" themes/icons/btn_enable.png" /> </a>
							</s:if>
							</td>
						</tr>
					</s:iterator>
					</s:if><s:else>
						<tr><td colspan="7">无记录</td></tr>
					</s:else>
				</tbody>
			</table>
		</div>
		<div><input type="button" name="btn_Delete" class="o-btn SubmitButton" value="删 除" id="btn_Delete" onclick="deleteAll('ReptShow$ctl01$Chk_Num')"></div>
	</body>
</html>
